{% if response.HasType -%}
{%     if response.IsFile -%}
{%         if response.IsSuccess -%}
var responseStream_ = response_.Content == null ? System.IO.Stream.Null : await response_.Content.ReadAsStreamAsync().ConfigureAwait(false);
var fileResponse_ = new FileResponse((int)response_.StatusCode, headers_, responseStream_, {% if InjectHttpClient %}null{% else %}client_{% endif %}, response_); 
client_ = null; response_ = null; // response and client are disposed by FileResponse
return fileResponse_;
{%         else -%}
var objectResponse_ = await ReadObjectResponseAsync<{{ response.Type }}>(response_, headers_).ConfigureAwait(false);
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object);
{%         endif -%}
{%     else -%}
var objectResponse_ = await ReadObjectResponseAsync<{{ response.Type }}>(response_, headers_).ConfigureAwait(false);
{%         if response.IsSuccess -%}
{%             if operation.WrapResponse -%}
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>((int)response_.StatusCode, headers_, objectResponse_.Object); 
{%             else -%}
return objectResponse_.Object; 
{%             endif -%}
{%         endif -%}
{%         if response.IsSuccess == false -%}
{%             if response.InheritsExceptionSchema -%}
var responseObject_ = objectResponse_.Object != null ? objectResponse_.Object : new {{ response.Type }}();
responseObject_.Data.Add("HttpStatus", status_);
responseObject_.Data.Add("HttpHeaders", headers_);
responseObject_.Data.Add("HttpResponse", objectResponse_.Text);
{%                 if WrapDtoExceptions -%}
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", (int)response_.StatusCode, objectResponse_.Text, headers_, responseObject_);
{%                 else -%}
throw responseObject_;
{%                 endif -%}
{%             else -%}
throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescription }}", (int)response_.StatusCode, objectResponse_.Text, headers_, objectResponse_.Object, null);
{%             endif -%}
{%         endif -%}
{%     endif -%}
{% elseif response.IsSuccess -%}
{%     if operation.HasResultType -%}
{%         if operation.WrapResponse -%}
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>((int)response_.StatusCode, headers_, default({{ operation.UnwrappedResultType }})); 
{%         else -%}
return default({{ operation.UnwrappedResultType }});
{%         endif -%}
{%     else -%}
{%         if operation.WrapResponse -%}
return new {{ ResponseClass }}((int)response_.StatusCode, headers_); 
{%         else -%}
return;
{%         endif -%}
{%     endif -%}
{% else -%}{% comment %} implied: `if !response.HasType` so just read it as text {% endcomment %}
string responseText_ = ( response_.Content == null ) ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new {{ ExceptionClass }}("{{ response.ExceptionDescription }}", (int)response_.StatusCode, responseText_, headers_, null);
{% endif -%}